import requests

class AppError(Exception):
    def __init__(self,id:str ,*args: object) -> None:
        self.id = id
        super().__init__(*args)

def fetch_remote_file(file:str, target:str) -> None:
    f=requests.get(target)
    with open(file,"wb") as data:
        data.write(f.content)

def once(f):
    runned = False
    result = None
    def wrapper(*args, **kwargs):
        nonlocal runned
        nonlocal result
        if runned: return result
        runned = True
        result = f(*args,**kwargs)
        return result
    return wrapper

def track_stream(output, target) -> None:
    while True:
        data = target.read(1)
        if not data: break
        output.write(data)

def cached(f):
    cache = {}
    def wrapped(*args,**kwargs):
        h = hash(args, kwargs)
        c = cache.get(h, None)
        if c: return c
        r = f(*args, **kwargs)
        cache[h]=r
        return r
    return wrapped